package br.com.sgdc.view.action;

import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.security.NoSuchAlgorithmException;
import java.sql.SQLException;

import br.com.sgdc.Facade;
import br.com.sgdc.view.WindowAlteraSenha;

public class ActionWindowAlteraSenha implements WindowListener {
	private WindowAlteraSenha window;
	private Facade facade;
	
	public ActionWindowAlteraSenha(WindowAlteraSenha window) {
		this.window = window;
		this.facade = new Facade();
	}

	@Override
	public void windowActivated(WindowEvent arg0) {

	}

	@Override
	public void windowClosed(WindowEvent arg0) {

	}

	@Override
	public void windowClosing(WindowEvent arg0) {

	}

	@Override
	public void windowDeactivated(WindowEvent arg0) {

	}

	@Override
	public void windowDeiconified(WindowEvent arg0) {

	}

	@Override
	public void windowIconified(WindowEvent arg0) {

	}

	@Override
	public void windowOpened(WindowEvent event) {
		if(event.getSource() == window.window){
			try {
				facade.setConfiguracaoSistema(facade.getConfiguracaoSistemaDao().listaConfiguracaoSistema());
				window.usuarioTextField.setText(facade.getConfiguracaoSistema().getUsuario());
				
			} catch (NoSuchAlgorithmException e) {
				e.printStackTrace();
			} catch (SQLException e) {
				e.printStackTrace();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
